package com.zx.task.manager.param;

import com.zx.validation.annotation.ParameterValidation;
import com.zx.validation.enums.DateTimeFormatEnum;
import com.zx.validation.enums.ValidateRulesEnum;
import com.zx.validation.groups.Create;
import com.zx.validation.groups.Query;
import com.zx.validation.groups.StatusUpdate;
import com.zx.validation.groups.Update;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Set;

/**
 * <p>
 * description: 任务信息参数 <br>
 * create: 2025-10-13 20:15
 * </p>
 *
 * @author zhou  xun
 */
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@Data
public class TasksParam implements Serializable, Create, Update, Query, StatusUpdate {
    /**
     * 任务ID
     */
    @ParameterValidation(index = 0, desc = "任务ID", rules = {ValidateRulesEnum.NOT_NULL})
    private String id;

    /**
     * 父任务ID
     */
    private String parentId;

    /**
     * 任务编号
     */
    // @ParameterValidation(index = 0, desc = "任务编号", rules = {ValidateRulesEnum.NOT_NULL, ValidateRulesEnum.LENGTH}, length = "1~50", groups = {Update.class})
    private String taskNo;

    /**
     * 任务类型ID
     */
    @ParameterValidation(index = 0, desc = "任务类型ID", rules = {ValidateRulesEnum.NOT_NULL, ValidateRulesEnum.LENGTH}, length = "1~32")
    private String taskTypeId;

    /**
     * 任务标题
     */
    @ParameterValidation(index = 0, desc = "任务标题", rules = {ValidateRulesEnum.NOT_NULL, ValidateRulesEnum.LENGTH}, length = "1~200")
    private String title;

    /**
     * 优先级：1-紧急 2-高 3-中 4-低
     */
    @ParameterValidation(index = 0, desc = "优先级", rules = {ValidateRulesEnum.NOT_NULL})
    private Integer priority;

    /**
     * 任务状态(1-待发布 2-已发布 3-进行中 4-已完成 5-已关闭 6-已取消)
     */
    @ParameterValidation(index = 0, desc = "任务状态", rules = {ValidateRulesEnum.NOT_NULL})
    private Integer status;

    /**
     * 创建人ID
     */
    private String creatorId;

    /**
     * 创建人姓名
     */
    private String creatorName;

    /**
     * 指定处理人ID
     */
    @ParameterValidation(index = 0, desc = "指定处理人ID", rules = {ValidateRulesEnum.LENGTH}, length = "0~32")
    private String assigneeId;

    /**
     * 指定处理人姓名
     */
    @ParameterValidation(index = 0, desc = "指定处理人姓名", rules = {ValidateRulesEnum.LENGTH}, length = "0~50")
    private String assigneeName;

    /**
     * 计划开始时间
     */
    @ParameterValidation(index = 0, desc = "计划开始时间", rules = {ValidateRulesEnum.NULL_DATE_TIME}, dateFormat = DateTimeFormatEnum.DATE_TIME)
    private LocalDateTime plannedStartTime;

    /**
     * 计划结束时间
     */
    @ParameterValidation(index = 0, desc = "计划结束时间", rules = {ValidateRulesEnum.NULL_DATE_TIME}, dateFormat = DateTimeFormatEnum.DATE_TIME)
    private LocalDateTime plannedEndTime;

    /**
     * 实际开始时间
     */
    private LocalDateTime actualStartTime;

    /**
     * 实际结束时间
     */
    private LocalDateTime actualEndTime;

    /**
     * 严重程度：1-致命 2-严重 3-一般 4-轻微
     */
    //此处不要验证非空 只能是bug类型任务时，必填,业务逻辑判断
    //@ParameterValidation(index = 0, desc = "严重程度", rules = {ValidateRulesEnum.NOT_NULL}, groups = {Create.class, Update.class})
    private Integer severity;

    /**
     * 来源
     */
    @ParameterValidation(index = 0, desc = "来源", rules = {ValidateRulesEnum.LENGTH}, length = "0~100")
    private String source;

    /**
     * 附件路径
     */
    @ParameterValidation(index = 0, desc = "附件路径", rules = {ValidateRulesEnum.NULL_LENGTH}, length = "0~500")
    private String attachment;

    /**
     * 创建者
     */
    private String createBy;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 更新者
     */
    private String updateBy;

    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    /**
     * 备注
     */
    @ParameterValidation(index = 0, desc = "备注", rules = {ValidateRulesEnum.NULL_LENGTH}, length = "0~200")
    private String remark;

    /**
     * 任务描述
     */
    @ParameterValidation(index = 0, desc = "任务描述", rules = {ValidateRulesEnum.LENGTH}, length = "0~1000")
    private String description;

    /**
     * 当前页码
     */
    @ParameterValidation(index = 0, desc = "当前页码", rules = {ValidateRulesEnum.NUMBER_MIN}, numberMin = 1)
    private Long pageNum;

    /**
     * 每页条数
     */
    @ParameterValidation(index = 0, desc = "每页条数", rules = {ValidateRulesEnum.NUMBER_MIN, ValidateRulesEnum.NUMBER_MAX}, numberMin = 1, numberMax = 1000)
    private Long pageSize;

    /**
     * 进度百分比(0-100)
     */
    //编辑不验证进度,单独的接口更新进度并验证状态
    //@ParameterValidation(index = 0, desc = "进度百分比", rules = {ValidateRulesEnum.NUMBER_MIN, ValidateRulesEnum.NUMBER_MAX}, numberMin = 0, numberMax = 100, groups = {Update.class})
    private Integer progressPercent;

    /**
     * 创建时间开始
     * 用于时间范围查询，当只提供开始时间时，查询大于等于该时间的记录
     */
    @ParameterValidation(index = 0, desc = "创建时间开始", rules = {ValidateRulesEnum.NULL_DATE_TIME}, dateFormat = DateTimeFormatEnum.DATE_TIME)
    private LocalDateTime createTimeStart;

    /**
     * 创建时间结束
     * 用于时间范围查询，当只提供结束时间时，查询小于等于该时间的记录
     */
    @ParameterValidation(index = 0, desc = "创建时间结束", rules = {ValidateRulesEnum.NULL_DATE_TIME}, dateFormat = DateTimeFormatEnum.DATE_TIME)
    private LocalDateTime createTimeEnd;

    @Override
    public Set<String> getCreateGroupFields() {
        return Set.of("taskTypeId", "title", "priority", "assigneeId", "assigneeName", "plannedStartTime",
                "plannedEndTime", "source", "attachment", "remark", "description");
    }

    @Override
    public Set<String> getUpdateGroupFields() {
        return Set.of("id", "taskTypeId", "title", "priority", "assigneeId", "assigneeName", "plannedStartTime",
                "plannedEndTime", "source", "attachment", "remark", "description");
    }

    @Override
    public Set<String> getQueryGroupFields() {
        return Set.of("taskTypeId", "title", "priority", "status", "assigneeId", "assigneeName", "plannedStartTime",
                "plannedEndTime", "source", "createTimeStart", "createTimeEnd", "pageNum", "pageSize");
    }

    @Override
    public Set<String> getStatusUpdateGroupFields() {
        return Set.of("id", "status");
    }
}